using UnityEngine;
using System.Collections;

public class MouseController : MonoBehaviour {
	
	public static MouseController instance;
	public enum CursorType{
		HAND = 0,
		AIM,
		DEFAULT,
		FORBIDDEN,
		KNIFE,
		LOOT,
		WALK,
        EYE,
        AIMACTIVE,
        KNIFEACTIVE,
	}
	public Texture2D[] cursorTextures;  
	public Vector2[] cursorOffsets;
	public int cursorSize;  
	public bool drawCursor;
	public Vector2 cursorRelativePosition;
	
	private Texture2D activeCursor;
	private Vector2 activeOffset;
	private float adjustedCursorSizeX;
	private float adjustedCursorSizeY;
	
	void Start()
	{
		drawCursor = true;
		instance = this;
	    Screen.showCursor = false;
		adjustedCursorSizeX = (float)Screen.width * cursorSize/100;
		adjustedCursorSizeY = (float)Screen.height * cursorSize/100;
		adjustedCursorSizeY *= (float)Screen.width/Screen.height;
		Debug.Log("cursor" + adjustedCursorSizeX +" "+ adjustedCursorSizeY);
        ChangeCursor(CursorType.DEFAULT);
	}
	void Update(){
		/*if (Input.GetKeyDown(KeyCode.Alpha0) )
			ChangeCursor(CursorType.ACTION);
		if (Input.GetKeyDown(KeyCode.Alpha1) )
			ChangeCursor(CursorType.TARGET);
		if (Input.GetKeyDown(KeyCode.Alpha2) )
			ChangeCursor(CursorType.DEFAULT);
		if (Input.GetKeyDown(KeyCode.Alpha3) )
			ChangeCursor(CursorType.FORBIDDEN);
		if (Input.GetKeyDown(KeyCode.Alpha4) )
			ChangeCursor(CursorType.KNIFE);
		if (Input.GetKeyDown(KeyCode.Alpha5) )
			ChangeCursor(CursorType.LOOT);
		if (Input.GetKeyDown(KeyCode.Alpha6) )
			ChangeCursor(CursorType.WALK);*/
	}
	void OnGUI()
	{
		if(activeCursor != null && drawCursor)
		{
		    GUI.DrawTexture (new Rect
				(Event.current.mousePosition.x - (activeOffset.x*adjustedCursorSizeX), 
				 Event.current.mousePosition.y - (activeOffset.y*adjustedCursorSizeY), 
				 adjustedCursorSizeX, adjustedCursorSizeY), 
				activeCursor);
		}
	}
	public void ChangeCursor(CursorType type){
		this.activeCursor = cursorTextures[(int)type];
		this.activeOffset = cursorOffsets[(int)type];
	}
}
